/* This file is part of xREL
 *
 * Copyright (C) 2012 Timo Zimmermann <xrel@timozimmermann.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

import QtQuick 1.1
import com.xrel 1.0
import "../components"

Item {
    id: root
    width: parent.width - 12
    anchors.horizontalCenter: parent.horizontalCenter
    height: 92

    state: ext_info_type

    ListItemHighlight { id: highlight }

    Row {
        anchors.fill: parent
        spacing: 12

        Rectangle {
            id: typeRect
            anchors.top: parent.top
            height: parent.height
            width: 24
            color: "black"
            radius: 4

            Label {
                id: typeLabel
                anchors.centerIn: parent
                rotation: -90
                text: "Type"
                color: "white"
                font.pixelSize: 14
                smooth: true
            }
        }

        Column {
            anchors.top: parent.top
            width: parent.width - typeRect.width - parent.spacing
            Label {
                id: titleLabel
                text: ext_info_title
            }
            Label {
                text: dirname
                font.pixelSize: 20
                color: "darkgray"
            }

            Item {
                id: infoLabelsItem
                height: childrenRect.height
                width: parent.width

                Label {
                    id: groupLabel
                    anchors.left: parent.left
                    text: group_name + " - "
                    font.pixelSize: 20
                    color: "darkgray"
                }

                Label {
                    id: infoLabel
                    anchors.left: groupLabel.right
                    text: size_mb + " MB"
                    font.pixelSize: 20
                    color: "darkgray"
                }

                Label {
                    id: dateLabel
                    anchors.right: parent.right
                    text: Qt.formatDateTime(convertDateTime(pub_time), "dd.MM.yy hh:mm")
                    font.pixelSize: 20
                    color: "darkgray"
                }
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        onPressed: highlight.opacity = 1.0
        onReleased: highlight.opacity = 0.0
        onPositionChanged: highlight.opacity = 0.0
        onClicked: parent.ListView.view.showReleaseP2PInfo(id)
    }

    states: [
        State {
            name: "movie"
            PropertyChanges { target: typeLabel; text: "MOVIE" }
            PropertyChanges { target: typeRect; color: "cyan" }
        },
        State {
            name: "tv"
            PropertyChanges { target: typeLabel; text: "TV" }
            PropertyChanges { target: typeRect; color: "brown" }
            PropertyChanges { target: infoLabel; text: createSeasonEposideString(tv_season, tv_episode) + size_mb + " MB" }
        },
        State {
            name: "console"
            PropertyChanges { target: typeLabel; text: "CONSOLE" }
            PropertyChanges { target: typeRect; color: "purple" }
        },
        State {
            name: "game"
            PropertyChanges { target: typeLabel; text: "GAME" }
            PropertyChanges { target: typeRect; color: "#808000" }
        },
        State {
            name: "xxx"
            PropertyChanges { target: typeLabel; text: "XXX" }
            PropertyChanges { target: typeRect; color: "red" }
        },
        State {
            name: "software"
            PropertyChanges { target: typeLabel; text: "Software" }
            PropertyChanges { target: typeRect; color: "black" }
        }
    ]

    function createSeasonEposideString(season, episode) {
        if(season === "" && episode === "") return "";
        var seasonString = season === "" ? "" : ("S"+season);
        var episodeString = episode === "" ? "" : ("E"+episode);
        return "<b>" + seasonString + episodeString + "</b> - ";
    }

    function convertDateTime(unix_time) {
        var datetime = new Date(unix_time*1000);
        return datetime;
    }
}
